#include <iostream>
#include <math.h>
using namespace std;

#include "CQuadEq.h"
void CQuadEq::FindRoot()
{
    d = pow(b, 2) - 4 * a * c;
    if (a == 0)
    {
        x1 = -c / b;
    }
    else
    {
        if (d > 0)
        {
            x1 = (-b - sqrt(d)) / (2 * a);
            x2 = (-b + sqrt(d)) / (2 * a);
        }
        else if (d == 0)
        {
            x1 = -b / (2 * a);
            x2 = x1;
        }
    }
}

void CQuadEq::Show()
{
    FindRoot();
    if (a == 0)
    {
        cout << "x1 = " << x1 << endl;
        cout << "x2不存在" << endl;
    }
    else if (d < 0)
    {
        cout << "x1 = " << -b / (2 * a) << "-" << sqrt(-d) / (2 * a) << "i" << endl;
        cout << "x2 = " << -b / (2 * a) << "+" << sqrt(-d) / (2 * a) << "i" << endl;
    }
    else
    {
        cout << "x1 = " << x1 << endl;
        cout << "x2 = " << x2 << endl;
    }
}


CQuadEq::CQuadEq()
{
}

CQuadEq::CQuadEq(float a, float b, float c)
{
    this->a = a;
    this->b = b;
    this->c = c;
}